package com.hong.day04;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: csh
 * @Date: 2019/11/24 22:31
 * @Description:
 */
public class VariableTest {

    public static void main(String[] args) {
        //1.得到ProcessEngine
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到TaskService
        TaskService taskService = defaultProcessEngine.getTaskService();
        //3.流程定义的key问题，holiday4
        String key = "holiday4";
        List <Task> lishi = taskService.createTaskQuery().processDefinitionKey(key)
                .taskAssignee("zhaoliu").list();
        //4.判断task!=null说明当前用户有任务
        for (Task task : lishi) {
            if(task!=null){
                taskService.complete(task.getId());
                System.out.println("任务执行完毕!");
            }
        }

    }

  /*  public static void main2(String[] args) {
        //1.得到ProcessEngine
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到runtimeService
        RuntimeService runtimeService = defaultProcessEngine.getRuntimeService();
        //3.流程定义的key问题，holiday4
        String key = "holiday4";
        Map<String,Object> map = new HashMap <String, Object>();
        Holiday holiday = new Holiday();
        holiday.setNum(5F);
        map.put("holiday",holiday);
        //4.启动流程实例，并且设置流量的值
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key, map);

        //5.输出实例信息
        System.out.println(processInstance.getName());
        System.out.println(processInstance.getProcessDefinitionId());

    }*/
}
